<?php
/*------------------------------------------------------------------------
 * WeixinController.class.php 
 *
 * 微信相关接口
 * 	
 * Created on 2015-11-19
 *
 * Author: hwc123 <hwc123@139.com>
 * 
 * Copyright (c) 2015 http://www.qingtajiao.com All rights reserved.
 * ------------------------------------------------------------------------
 */

namespace Api\Controller;
class WeixinController extends CommonController{

	// 获取微信配置
	public function get_config(){
		$user_id = $this->user_id();
		$where['user_id'] = $user_id;
		$data = D('UserWeixinConfig')->where($where)->find();

		$this->success('获取数据成功！', $data);
	}
	// 设置微信配置
	public function set_config(){
		$user_id = $this->user_id();
		$data['token']     = $this->_post('token', 'Token不能为空！');
		$data['appid']     = $this->_post('appid', 'App ID不能为空！');
		$data['appsecret'] = $this->_post('appsecret', 'App Secret不能为空！');

		$where['user_id'] = $user_id;
		if(D('UserWeixinConfig')->where($where)->count()){
			$data['edit_time'] = time();
			D('UserWeixinConfig')->where($where)->save($data);
		}else{
			$data['user_id']     = $user_id;
			$data['create_time'] = time();
			D('UserWeixinConfig')->add($data);
		}
		$this->success('设置成功！');
	}
}